#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//	system("start https://www.lanqiao.cn/problems/4510/learning/");

	int n, q;
	cin >> n;

	vector<int> a(n + 1);
	vector<vector<int>> cnt(101);	// cnt[a[i]][j] = i 表示 a[i] 第 j 次出现在 i 位置

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]].push_back(i);
	}

	cin >> q;
	while (q--) {
		int l1, l2, r1, r2;
		cin >> l1 >> r1 >> l2 >> r2;

		int ans = 0;

		for (int i = l1; i <= r1; i++) {
			int idxL = lower_bound(cnt[a[i]].begin(), cnt[a[i]].end(), l2) - cnt[a[i]].begin();
			int idxR = upper_bound(cnt[a[i]].begin(), cnt[a[i]].end(), r2) - cnt[a[i]].begin();

			if (idxL == cnt[a[i]].size())
				continue;

			ans += idxR - idxL;
		}
		cout << ans << endl;
	}

	return 0;
}
